package com.cy.pj.sys.service.impl;

import com.cy.pj.common.annoation.RequiredLog;
import com.cy.pj.sys.service.SysLogService;
import com.cy.pj.common.annoation.RequiredTime;
import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public  class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;

//  public SysLogServiceImpl(SysLogDao sysLogDao){
//        this.sysLogDao=sysLogDao;
//  }
    @RequiredTime
    @RequiredLog(operation = "查询日志") //由此注解描述的方法为日志切入点方法
    @Override
    public List<SysLog> findLogs(SysLog sysLog) {
        System.out.println("log.find.thread->"+Thread.currentThread().getName());
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return sysLogDao.selectLogs(sysLog);
    }

    @RequiredLog(operation = "查询日志")
    @Override
    public SysLog findById(Long id) {
        return sysLogDao.selectById(id);
    }

    @Async
    @Override
    public void saveLog(SysLog sysLog) {
        System.out.println("log.find.thread->"+Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        sysLogDao.insertLog(sysLog);
    }

    @RequiredLog(operation = "删除日志")
    @Override
    public int deleteById(Long... id) {
        return sysLogDao.deleteById(id);
    }
}